#include <fstream>
#include <iostream>
#include <string>
using namespace std;

#include "TTree.h"
#include "TCanvas.h"

void plots(TString dataFile) {
  ifstream fh(dataFile.Data());
  if(!fh.is_open())
    {
      cerr << "Error opening data file" << endl; 
      return;
    }
  
  int timestamp;
  int revision;
  int numberofcodefiles;
  int numberoflinesincodefiles;
  int numberofheaderfiles;
  int sizeofproject;
  TTree *dataTree=new TTree("dataTree","dataTree");
  dataTree->Branch("timestamp", &timestamp, "timestamp/I");
  dataTree->Branch("revision", &revision, "revision/I");
  dataTree->Branch("numberofcodefiles", &numberofcodefiles, "numberofcodefiles/I");
  dataTree->Branch("numberoflinesincodefiles", &numberoflinesincodefiles, "numberoflinesincodefiles/I");
  dataTree->Branch("numberofheaderfiles", &numberofheaderfiles, "numberofheaderfiles/I");
  dataTree->Branch("sizeofproject", &sizeofproject, "sizeofproject/I");

  while (!fh.eof() )
    {
      fh >> timestamp >> revision >> numberofcodefiles >> numberoflinesincodefiles >> numberofheaderfiles >> sizeofproject;
      dataTree->Fill();
    }
  fh.close();

  TCanvas *c1=new TCanvas();
  TH2F *htemp;

  dataTree->Draw("numberofcodefiles:timestamp","","*C");
  htemp=(TH2F*)c1->GetPrimitive("htemp");
  htemp->SetTitle("");
  htemp->GetXaxis()->SetTimeDisplay(1);
  htemp->GetXaxis()->SetNdivisions(7);
  htemp->GetXaxis()->SetTitle("Date");
  htemp->GetYaxis()->SetTitle("# Of Code Files");
  c1->SaveAs("numberofcodefiles.png");
  c1->Clear();

  dataTree->Draw("numberoflinesincodefiles:timestamp","","*C");
  htemp=(TH2F*)c1->GetPrimitive("htemp");
  htemp->SetTitle("");
  htemp->GetXaxis()->SetTimeDisplay(1);
  htemp->GetXaxis()->SetNdivisions(7);
  htemp->GetXaxis()->SetTitle("Date");
  htemp->GetYaxis()->SetTitle("# Of Lines Of Code");
  htemp->GetYaxis()->SetTitleOffset(1.4);
  c1->SaveAs("numberoflinesincodefiles.png");
  c1->Clear();

  dataTree->Draw("numberofheaderfiles:timestamp","","*C");
  htemp=(TH2F*)c1->GetPrimitive("htemp");
  htemp->SetTitle("");
  htemp->GetXaxis()->SetTimeDisplay(1);
  htemp->GetXaxis()->SetNdivisions(7);
  htemp->GetXaxis()->SetTitle("Date");
  htemp->GetYaxis()->SetTitle("# Of Classes");
  c1->SaveAs("numberofheaderfiles.png");
  c1->Clear();

  dataTree->Draw("sizeofproject:timestamp","","*C");
  htemp=(TH2F*)c1->GetPrimitive("htemp");
  htemp->SetTitle("");
  htemp->GetXaxis()->SetTimeDisplay(1);
  htemp->GetXaxis()->SetNdivisions(7);
  htemp->GetXaxis()->SetTitle("Date");
  htemp->GetYaxis()->SetTitle("Size Of Project (Mb)");
  c1->SaveAs("sizeofproject.png");
  c1->Clear();

  return;
}
